' !!!!!!!!!!  JAD ( .....)
'FileCopy SourceFile, DestinationFile    ' Copy source to target.
'FileLen ("TESTFILE") ' Returns file length (bytes).
'MkDir "MYDIR"   ' Make new directory or folder.
'RmDir "MYDIR"
'Dir

    'txtDisplay.SelStart = 0
    'txtDisplay.SelStart = Len(txtDisplay.Text)
    'txtDisplay.SelStart = 5
    'txtDisplay.SetFocus

    'txtDisplay.SelStart = 0
    'txtDisplay.SelLength = Len(txtDisplay.Text)
    'txtDisplay.SetFocus

    'txtDisplay.SelText = "NEW TEXT"
    'txtDisplay.SetFocus
    
Public Function SaveFls()

FileCopy "jarcopy\BR\a.class", TxtPath2.Text & TxtNameFileSave.Text & "\BR\a.class"
FileCopy "jarcopy\BR\b.class", TxtPath2.Text & TxtNameFileSave.Text & "\BR\b.class"
FileCopy "jarcopy\BR\BookReader.class", TxtPath2.Text & TxtNameFileSave.Text & "\BR\BookReader.class"
FileCopy "jarcopy\BR\c.class", TxtPath2.Text & TxtNameFileSave.Text & "\BR\c.class"
FileCopy "jarcopy\BR\d.class", TxtPath2.Text & TxtNameFileSave.Text & "\BR\d.class"
FileCopy "jarcopy\B0.PNG", TxtPath2.Text & TxtNameFileSave.Text & "\B0.PNG"
FileCopy "jarcopy\B1.PNG", TxtPath2.Text & TxtNameFileSave.Text & "\B1.PNG"
FileCopy "jarcopy\B2.PNG", TxtPath2.Text & TxtNameFileSave.Text & "\B2.PNG"
FileCopy "jarcopy\ENCODING.TXT", TxtPath2.Text & TxtNameFileSave.Text & "\ENCODING.TXT"
FileCopy "jarcopy\LOC.TXT", TxtPath2.Text & TxtNameFileSave.Text & "\LOC.TXT"
End Function

Public Function SaveJad()	' .......
If TxtNameFileSave.Text = "" Then
    'MsgBox "     ", vbInformation
    
Else
    txtjad = ""
    txtjad = "Manifest-Version: 1.0" & Chr(10)
    txtjad = txtjad & "MicroEdition-Configuration: CLDC-1.0" & Chr(10)
    txtjad = txtjad & "MIDlet-Name: " & TxtNameFileSave.Text & Chr(10)
    txtjad = txtjad & "TCBR-Platform: Generic version (all phones)" & Chr(10)
    txtjad = txtjad & "Created-By: Apache Ant 1.5.1" & Chr(10)
    txtjad = txtjad & "TCBR-Platform-Id: Platform_MIDP10" & Chr(10)
    txtjad = txtjad & "TCBR-ParamFormat: 2.0" & Chr(10)
    txtjad = txtjad & "MIDlet-Vendor: tequilacat" & Chr(10)
    txtjad = txtjad & "MIDlet-1: " & TxtNameFileSave.Text & ", , br.BookReader" & Chr(10)
    txtjad = txtjad & "MIDlet-Version: 1.6.10" & Chr(10)
    txtjad = txtjad & "MicroEdition-Profile: MIDP-1.0" & Chr(10)
    RichTextBoxTMP.Text = txtjad
    RichTextBoxTMP.SaveFile TxtPath2.Text & TxtNameFileSave.Text & "\META-INF\MANIFEST.MF", rtfText
    RichTextBoxTMP.Text = ""
    
End If
End Function

Public Function MkFolderForJar()
If TxtNameFileSave.Text = "" Then
    MsgBox "     ", vbInformation
    
Else
    If Len(TxtPath2.Text) > 3 And Mid(TxtPath2.Text, Len(TxtPath2.Text), 1) <> "\" Then
        TxtPath2.Text = TxtPath2.Text & "\"
    End If
    
On Error Resume Next
MkDir TxtPath2.Text & TxtNameFileSave.Text
MkDir TxtPath2.Text & TxtNameFileSave.Text & "\" & "br"
MkDir TxtPath2.Text & TxtNameFileSave.Text & "\" & "META-INF"

End If
End Function

Private Sub CommandClr_Click()
RichTextBox1.Text = ""
End Sub

Private Sub CommandOpenFile_Click()
If File1.filename <> "" Then
RichTextBox1.LoadFile TxtPath.Text, rtfText
Else
MsgBox " ", vbInformation
End If
End Sub

Private Sub CommandSave_Click()
    MkFolderForJar
    SaveJad
    SaveFls
    proptop = ""

If TxtNameFileSave.Text = "" Then
Else

    If RichTextBox1.Text = "" Then
    MsgBox "   ", vbInformation
    Else
 
        lentxt = Len(RichTextBox1.Text)
        PathToSave = TxtPath2.Text & TxtNameFileSave.Text & "\"
        prcount = Int(lentxt / 62000) + 1
        pr1 = 0
        tmp1 = ""
        tmp2 = ""
        While pr1 < prcount
        RichTextBoxTMP.Text = Mid(RichTextBox1.Text, 1 + 62000 * pr1, 62000)
            If pr1 = 0 Then
                RichTextBoxTMP.SaveFile PathToSave & "textfile" & ".txt", rtfText
                tmp1 = "J/" & "textfile" & ".txt" & ".label=" & TxtNameFileSave.Text & "(" & (pr1 + 1) & ")"
                ppr2len = Len(tmp1)
                ppr3 = 1
                    While ppr3 <= ppr2len
                        tmp2 = tmp2 & Chr(0) & Mid(tmp1, ppr3, 1)
                        ppr3 = ppr3 + 1
                    Wend
                tmp2 = tmp2 & Chr(0) & Chr(10)
            Else
            RichTextBoxTMP.SaveFile PathToSave & "textfile" & pr1 & ".txt", rtfText
            tmp1 = "J/" & "textfile" & ".txt" & ".label=" & TxtNameFileSave.Text & "(" & (pr1) & ")"
            
            ppr2len = Len(tmp1)
            ppr3 = 1
            While ppr3 <= ppr2len
                tmp2 = tmp2 & Chr(0) & Mid(tmp1, ppr3, 1)
                ppr3 = ppr3 + 1
            Wend
            tmp2 = tmp2 & Chr(0) & Chr(10)
            End If
        RichTextBoxTMP.Text = ""
        pr1 = pr1 + 1
        Wend
        
        
txttop = Array("bgcolor=16777215", "fgcolor=0", "blint=100", "wrap=-1", "il=0", "mgleft=0", "mgtop=0", "mgright=0", "mgbottom=0", "sbpos=0", "deffont=0", "hasdirbuttons=true", "autoadv=t", "ascr=3000")
tmptxt = Chr(254) & Chr(255)

ppr1 = 0
While ppr1 <= 13
    ppr2 = txttop(ppr1)
    ppr2len = Len(ppr2)
    ppr3 = 1
        While ppr3 <= ppr2len
        tmptxt = tmptxt & Chr(0) & Mid(ppr2, ppr3, 1)
        ppr3 = ppr3 + 1
        Wend
        tmptxt = tmptxt & Chr(0) & Chr(10)
    ppr1 = ppr1 + 1
Wend

RichTextBoxTMP.Text = tmptxt & tmp2
RichTextBoxTMP.SaveFile PathToSave & "props.ini", rtfText
          
        
    End If
End If



    ' RichTextBoxTMP.Text = txtjad
    ' RichTextBoxTMP.SaveFile TxtPath2.Text & TxtNameFileSave.Text & ".jad", rtfText
    ' RichTextBoxTMP.Text = ""

End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
TxtPath.Text = File1.Path
TxtPath2.Text = File1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
TxtPath.Text = Dir1.Path
TxtPath2.Text = Dir1.Path
End Sub

Private Sub File1_Click()
    If Len(File1.Path) > 3 And Mid(File1.Path, Len(File1.Path), 1) <> "\" Then
        TxtPath.Text = File1.Path & "\" & File1.filename
    Else
        TxtPath.Text = File1.Path & File1.filename
    End If

End Sub

Private Sub File1_DblClick()
    If Len(File1.Path) > 3 And Mid(File1.Path, Len(File1.Path), 1) <> "\" Then
        TxtPath.Text = File1.Path & "\" & File1.filename
    Else
        TxtPath.Text = File1.Path & File1.filename
    End If
RichTextBox1.LoadFile TxtPath.Text, rtfText
End Sub

Private Sub Form_Load()
Dir1.Path = Drive1.Drive
File1.Path = Dir1.Path
TxtPath.Text = File1.Path
TxtPath2.Text = File1.Path
End Sub


Private Sub RichTextBox1_Change()
Label8.Caption = Int(Len(RichTextBox1.Text) / 62000) + 1
End Sub

Private Sub RichTextBox1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbKeyRButton Then
MsgBox "Ctrl+C " & Chr(10) & "Ctrl+X " & Chr(10) & "Ctrl+V " & Chr(10) & Chr(10) & "Ctrl+Home  " & Chr(10) & "Ctrl+End  " & Chr(10) & Chr(10) & "Ctrl+Home Shift Ctrl+End  ", vbInformation
End If
End Sub

Private Sub TxtNameFileSave_Change()
If Len(TxtNameFileSave.Text) > 8 Then
MsgBox " ", vbInformation

TxtNameFileSave.Text = Mid(TxtNameFileSave.Text, 1, 8)
End If
End Sub
